<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>

<body>
    <script src="./js/aes.js"></script>
    <script src="./js/mode-ecb.js"></script>
    <script src="./js/pad-nopadding.js"></script>
    <script>
        // AES加密方法,encrypt：要加密的数据
        function aesEncrypt(encrypt) {
            var aesPrivateKey = '1234567890123456'; //密钥
            var key = CryptoJS.enc.Utf8.parse(aesPrivateKey);
            var srcs = CryptoJS.enc.Utf8.parse(JSON.stringify(encrypt));
            var encrypted = CryptoJS.AES.encrypt(srcs, key, {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            });
            return encrypted.toString();
        }

        // AES 解密方法
        function aesDecrypt(decryptString) {
            var aesPrivateKey = '1234567890123456'; //密钥
            var key = CryptoJS.enc.Utf8.parse(aesPrivateKey);
            var decrypt = CryptoJS.AES.decrypt(decryptString, key, {
                mode: CryptoJS.mode.ECB,
                padding: CryptoJS.pad.Pkcs7
            });
            return CryptoJS.enc.Utf8.stringify(decrypt).toString();
        }
        //如何调用?举例
        var data1 = {
            "registFloor": "2",
            "endTime": "2020-03-16 17:32"
        };
        var AES = aesEncrypt(data1);
        console.log(AES);
        var AFTERAES = aesDecrypt(AES);
        console.log(AFTERAES);
    </script>
</body>

</html>